package lerry.load.loader;

import flash.display.Loader;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.net.URLRequest;
import flash.utils.Function;

class SWFLoader extends EventDispatcher{
	private var loader:Loader;
	private var cb:Function;
	public function new() {
		super();
		loader=new Loader();
	}
	public function load(url:String,?callBack:Function):Void {
		cb=callBack;
		loader.load(new URLRequest(url));
		loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoadCom);
	}
	function onLoadCom(event:Event):Void {
		loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,onLoadCom);
		if(cb!=null)cb();
		dispatchEvent(new Event(Event.COMPLETE));
	}
	public function getClass(name:String):Dynamic{
		var cl = loader.contentLoaderInfo.applicationDomain.getDefinition(name);
		return cl;
	}
	public function getClassInstance(name:String):Dynamic {
		var cl = loader.contentLoaderInfo.applicationDomain.getDefinition(name);
		var ins = Type.createEmptyInstance(cl);
		return ins;
	}
	public function getContent():Dynamic{
		return loader.content;
	}
}
